package com.hyzh.latte.sandtable.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hyzh.latte.sandtable.pojo.Vector_Line_2D;
import com.hyzh.latte.sandtable.pojo.Vector_Point_2D;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
@DS("sadt")
public interface VectorMapper {
    @Insert("INSERT INTO ${area} (start_x, start_y, end_x, end_y, length, geom) " +
            "VALUES (#{road.startX}, #{road.startY}, #{road.endX}, #{road.endY}, " +
            "ST_Length(ST_Transform(ST_MakeLine(ST_SetSRID(ST_Point(#{road.startX}, #{road.startY}), 4326), ST_SetSRID(ST_Point(#{road.endX}, #{road.endY}), 4326)), 3857)), " +
            "ST_MakeLine(ST_SetSRID(ST_Point(#{road.startX}, #{road.startY}), 4326), ST_SetSRID(ST_Point(#{road.endX}, #{road.endY}), 4326))" +
            ")")
    void insertRoad(@Param("road") Vector_Line_2D road, @Param("area") String area);

    @Insert("INSERT INTO ${area} (x, y, geom) " +
            "VALUES (#{node.x}, #{node.y}, " +
            "ST_SetSRID(ST_MakePoint(#{node.x}, #{node.y}), 4326))")
    void insertNode(@Param("node") Vector_Point_2D node, @Param("area") String area);

}
